package com.riant.cert;

import org.apache.commons.codec.binary.Base64;

import java.io.FileInputStream;
import java.math.BigInteger;
import java.security.cert.Certificate;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;

public class TestCert {
    public static void main(String[] args)throws Exception {
        CertificateFactory cf = CertificateFactory.getInstance("X.509");
        FileInputStream in = new FileInputStream("C:\\Users\\zhangbin4.CITICCARDINS\\IdeaProjects\\javase-test\\src\\main\\java\\com\\riant\\cert\\2048test.cer");
        Certificate c = cf.generateCertificate(in);
        in.close();
        X509Certificate t = (X509Certificate) c;
        System.out.println("版本号 " + t.getVersion());
        System.out.println("序列号 " + t.getSerialNumber().toString(16));
        System.out.println("全名 " + t.getSubjectDN());
        System.out.println("签发者全名 " + t.getIssuerDN());
        System.out.println("有效期起始日 " + t.getNotBefore());
        System.out.println("有效期截至日 " + t.getNotAfter());
        System.out.println("签名算法 " + t.getSigAlgName());
        System.out.println("签名" + Base64.encodeBase64String(t.getSignature()));
        System.out.println("公钥" + Base64.encodeBase64String(t.getPublicKey().getEncoded()));
        BigInteger bigInteger=new BigInteger("10");
        System.out.println(bigInteger.toString(16));
    }
}
